SELECT a.ID, raion.name as raion_name, a.ADR_STREET, a.ADR_DOM, a.SPM, a.KOMNAT, a.SPROOM, a.price, a.GOSTIN, a.COMMENT_NIGHT, a.REMOTE, a.SHOWER_CUBICLE, a.SHOWER, a.Geo_X, a.Geo_Y, coalesce(a.price, d.superprice) as realprice, coalesce(d.superprice, 0) as superprice, case when d.superprice is null then 'no' else 'yes' end as is_spo, e.rt as rating, a.N_INET, a.N_CONDITIONER, case when m.kv is null then 'no' else 'yes' end as in_mylist FROM kv a inner join raion on a.raion = raion.id left join ( select distinct kv from status_kv b where '2030-01-01' > b.d_begin and '2025-04-02' < b.d_end ) b on b.kv = a.id left join (select superprice as superprice, sum( LEAST(TO_DAYS(d_end), TO_DAYS('2030-01-01')) - GREATEST(TO_DAYS(d_begin), TO_DAYS('2025-04-02')) + 1 ) as superdays, kv, RANK from kv_p where '2030-01-01' >= d_begin and '2025-04-02' <= d_end group by kv) d on d.kv = a.id LEFT JOIN (SELECT kv, COUNT(kv) AS otzivcount, ROUND(SUM((chistota + vezlivost + osnashennost)/3)/COUNT(kv), 1) AS otzivrating FROM otzyv GROUP BY kv) o ON o.kv = a.id left join kv_r e on e.kv = a.id left join (select distinct kv from kv_mylist where user='') m on m.kv = a.id where d.superprice > 0 AND '2030-01-01'>='2025-04-02' and '2030-01-01'>=CURRENT_DATE() AND a.RANK >= 10000 and coalesce(a.price, d.superprice) between 1 and 100000 and coalesce(a.price, d.superprice) between 1500 and 100000 and a.GOSTIN='T' and GOSTIN='T' order by (price-superprice) DESC
Table 'etazhy_ru.otzyv' doesn't exist